//go:generate goversioninfo -icon=D:\black_mamba\resource\ico.ico -manifest=resource/goversioninfo.exe.manifest -platform-specific=true
package main

import (
	"black_mamba/global"
	"black_mamba/initialize"
	"black_mamba/utils"
	_ "embed"
	"gitee.com/wengo/windows_gui/xcc"
)

//go:embed ui/ui.zip
var layoutFile []byte

func main() {
	//fmt.Println(utils.Encrypt([]byte(utils.GeneratedMetadata1())))
	//amz := amazon.NewAmazon(amazon.Settings{
	//	//JA3:         "771,49196-49195-49200-49199-159-158-49188-49187-49192-49191-49162-49161-49172-49171-157-156-61-60-53-47-10,0-10-11-13-35-23-65281,29-23-24,0",
	//	//UserAgent:   "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50",
	//	//JA3: "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-21,29-23-24,0",
	//	//UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
	//	//JA3: "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0",
	//	//UserAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
	//	JA3:       "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0",
	//	UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
	//	BaseUri:   "https://www.amazon.com",
	//	Header:    nil,
	//	Cookies:   nil,
	//	Proxy:     `http://127.0.0.1:8080`,
	//	Debug:     false,
	//	//DebugLength: 0,
	//})
	//
	//amz.Ajax("/s/query", amazon.POST, map[string]interface{}{"content-type": "application/json"}, map[string]string{
	//	"k":    "generic",
	//	"s":    "review-rank",
	//	"page": "1",
	//	"rh":   fmt.Sprintf("n:%d,%s,p_89:Generic", 1055398, "p_72:1248916011"),
	//}, map[string]string{"page-content-type": "atf", "prefetch-type": "rq", "customer-action": "pagination"})

	////resp, _, _ := amz.Navigate("https://tls.peet.ws/api/all")
	////resp, _, _ := amz.Navigate("https://http2.akamai.com/demo")
	////resp, _, _ := amz.Navigate("https://http2.pro/api/v1")
	//resp, _, _ := amz.Navigate("/")
	//fmt.Println(resp.RawResponse.Request.Proto)

	//for i:=0; i < 2; i++ {
	//	go amz.Navigate("/")
	//}
	//_, document, _ := amz.Navigate("http")
	//fmt.Println(document)
	////html, _ := document.Html()
	//asin := `B09GVF3DHN`
	//_, _ = amz.ChangeAddress(document)
	//document, _ = amz.GetOfferListing(asin)
	//fmt.Println(amz.AddCartByOffers(document, asin, "AJD69LYDPC95", 1))
	//html2, _ := document.Html()
	//fmt.Println(gjson.Get(html2, "resource.url"))
	//_, document, _ = amz.Navigate(amazon.Cart)
	//html, _ := document.Html()
	//ioutil.WriteFile("cart.html", []byte(html), 0644)

	//a := app.New("")
	//
	///* 从内存中加载布局
	//a.LoadResourceZipMem(*(*int)(unsafe.Pointer(&layoutFile)), len(layoutFile), "resource.res", "")
	//// 从zip中加载布局文件
	//hWindow := a.LoadLayoutZipMem(*(*int)(unsafe.Pointer(&layoutFile)), len(layoutFile), "main.xml", "", 0)
	//*/
	//
	// 添加文件搜索路径, 你运行时需要改成自己的路径, 也可以使用相对路径
	//a.AddFileSearchPath(`D:\black_mamba\ui`)
	//// 从zip中加载资源文件
	//a.LoadResource("resource.res")
	//// 从zip中加载布局文件
	//hWindow := a.LoadLayout("main.xml", 0)
	//
	//if hWindow == 0 {
	//	panic("error")
	//}

	// 创建窗口对象
	//win := window.NewWindowByHandle(hWindow)
	initialize.App(layoutFile)
	//global.BM_DB = initialize.Gorm()
	global.BM_POOL = initialize.NewPool() // 初始化事件
	global.BM_API = utils.NewApi()        // 初始化事件
	global.BM_CONFIG = initialize.INIConfig()
	global.BM_QUEUE = initialize.NewArrayQueue()
	global.BM_EVENTBUS = initialize.NewEventBus()
	global.BM_CRONTAB = initialize.NewCrontab()
	global.BM_2CAPTCHA = initialize.New2Captcha()
	//global.BM_PHONE = initialize.NewPhone("smsman")
	//global.BM_PHONE.GetNumber(map[string]interface{}{"countryId": 110, "applicationId": 176})

	global.BM_PHONEPROVIDER = initialize.NewPhoneProvider("supersms")
	//global.BM_PHONEPROVIDER = initialize.NewPhoneProvider("fivesim")
	//countryCode, phoneNumber, err := global.BM_PHONE.GetNumber(map[string]interface{}{"country": "russia", "operator": "mts", "name": "amazon", "forwardingNumber": ""})

	// Read the entire file into a byte slice
	//bytes, err := ioutil.ReadFile("./small_7099227aae94427ab80a4f525cb8ec5f.gif")
	//if err != nil {
	//	log.Fatal(err)
	//}
	//
	//var base64Encoding string
	//
	//// Determine the content type of the image file
	//mimeType := http.DetectContentType(bytes)
	//fmt.Println(mimeType)
	//// Prepend the appropriate URI scheme header depending
	//// on the MIME type
	//switch mimeType {
	//case "image/jpeg":
	//	base64Encoding += "data:image/jpeg;base64,"
	//case "image/png":
	//	base64Encoding += "data:image/png;base64,"
	//case "image/gif":
	//	base64Encoding += "data:image/gif;base64,"
	//}

	//unbased, err := ioutil.ReadFile("./small_7099227aae94427ab80a4f525cb8ec5f.gif")
	//imgCoupon, err := gif.DecodeAll(bytes.NewReader(unbased))
	//imgCoupon.LoopCount = 0
	//fmt.Println(err)
	//// EncodeAll to the buffer
	//var buff bytes.Buffer
	//fmt.Println(gif.EncodeAll(&buff, imgCoupon))
	//fmt.Println("data:image/gif;base64," + base64.StdEncoding.EncodeToString(buff.Bytes()))
	// Append the base64 encoded output
	//base64Encoding += toBase64(bytes)

	// Print the full base64 representation of the image
	//fmt.Println(base64Encoding)

	//unbased, err := ioutil.ReadFile("./7099227aae94427ab80a4f525cb8ec5f .gif")
	//imgCoupon, err := gif.DecodeAll(bytes.NewReader(unbased))
	//imgCoupon.LoopCount = 0
	//// EncodeAll to the buffer
	//var buff bytes.Buffer
	//err = gif.EncodeAll(&buff, imgCoupon)
	//if err != nil {
	//	return
	//}
	//
	//img := global.BM_API.ConvertGif(base64.StdEncoding.EncodeToString(buff.Bytes()))
	//fmt.Println("ok", img)
	//cap := api2captcha.Normal{
	//	//File: "http://121.40.28.56/topamazon/_gif/small_7099227aae94427ab80a4f525cb8ec5f.gif",
	//	//File: "./small_7099227aae94427ab80a4f525cb8ec5f.gif",
	//	Base64: img,
	//}
	//
	//req := cap.ToRequest()
	//req.Params["method"] = "base64"
	//req.Params["min_len"] = strconv.FormatInt(int64(6), 10)
	//req.Params["max_len"] = strconv.FormatInt(int64(6), 10)
	//result, err := global.BM_2CAPTCHA.Solve(req)
	//fmt.Println(result, err)
	//a, _ := global.BM_5SIM.GetNumber("russia", "any", "amazon", "")
	//fmt.Println(a)
	//fmt.Println(global.BM_5SIM.GetCode(a.Taskid))
	//t, _ := global.BM_SMSMAN.GetNumber(10, 176)
	//fmt.Println(t)
	//fmt.Println(global.BM_SMSMAN.GetCode(122536394))
	//fmt.Println(global.BM_SUPERSMS.GetNumber("2", "IN", "31"))
	initialize.Pages()

	global.BM_WINDOW.AdjustLayout()
	global.BM_WINDOW.ShowWindow(xcc.SW_SHOW)
	global.BM_APP.Run()
	global.BM_APP.Exit()

	/**/

	//pages.InitInventoryPage(a, win, "InventoryMgr.xml")
	//
	//// 调整布局
	//win.AdjustLayout()
	//// 显示窗口
	//win.ShowWindow(xcc.SW_SHOW)
	//
	//a.Run()
	//a.Exit()
}
